package com.mars.boss.filer;

import com.mars.common.expetion.SysTipsException;
import com.mars.common.utils.MarsConstant;
import com.mars.common.utils.PasswordUtils;
import com.mars.common.utils.QAssert;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


//@Configuration
public class GlobalInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader(MarsConstant.GATEWAY_KEY);
        if (token.equals(MarsConstant.FEIGN_KEY)){
            return true;
        }
        QAssert.isTrue(token != null && PasswordUtils.isValidPassword(MarsConstant.GATEWAY_VALUE, token, null), SysTipsException.class, "请通过网关进行访问");
        return true;
    }
}
